package com.flong.spring.conditional;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Author:liangjl
 * @Date: 2020/6/10-20:33
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
public class WindowConditional implements Condition {


    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

            //获取系统环境变量
            Environment environment = context.getEnvironment();

            //获取到ioc使用的beanFactory
            ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
            //获取类加载器
            ClassLoader classLoader = context.getClassLoader();

            //获取registry
            BeanDefinitionRegistry registry = context.getRegistry();

            String osName = environment.getProperty("os.name");
            if (osName.contains("Window")) {
                return true;
            }

            return false;
    }
}
